package com.example.addemoone.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.graphics.toColorInt
import androidx.recyclerview.widget.RecyclerView
import com.example.addemoone.R

class ViewPager2Adapter: RecyclerView.Adapter<ViewPager2Adapter.ViewPager2Holder>() {

    data class Page(val color: String, val text: String)

    private val pages = listOf(
        Page("#FF5733", "Page 1"),
        Page("#33FF57", "Page 2"),
        Page("#3357FF", "Page 3")
    )
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ViewPager2Holder {
        return ViewPager2Holder(LayoutInflater.from(parent.context).inflate(R.layout.view_pager2_item, parent, false))
    }

    override fun onBindViewHolder(
        holder: ViewPager2Holder,
        position: Int
    ) {
        val pageData = pages[position]
        with(holder) {
            itemView.setBackgroundColor(pageData.color.toColorInt())
            textView.text = pageData.text
        }
    }

    override fun getItemCount(): Int {
        return pages.size
    }

    inner class ViewPager2Holder(itemView: View): RecyclerView.ViewHolder(itemView) {
        val textView = itemView.findViewById<TextView>(R.id.textView)
    }
}